<template>
  <div class="app-container">

    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch">
      <el-form-item label="所属行业" prop="industryId">
        <div class="w-[200px]">
          <el-select class="flex-1" v-model="queryParams.industryId" placeholder="请选择所属行业" clearable>
            <el-option class="flex-1" v-for="item in industryList" :key="item.industryId" :label="item.name"
              :value="item.industryId" />
          </el-select>
        </div>
      </el-form-item>
      <el-form-item label="所属系统" prop="systemName">
        <el-input style="width: 200px;" v-model="queryParams.systemName" placeholder="请输入所属系统" clearable
          @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item label="所属单位" prop="merchantName">
        <el-input v-model="queryParams.merchantName" placeholder="请输入所属单位" clearable style="width: 200px"
          @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="noticeList">
      <!-- 
        序号、内容、投放形式、所属行业、
        所属系统、所属单位、单位地址、
        法人姓名、法人电话、单位电话、
        创建时间、状态、操作人员
        -->
      <el-table-column label="序号" align="center" type="index" width="55">
        <template #default="{ $index }">
          {{ (queryParams.currentPage - 1) * queryParams.pageSize + $index + 1 }}
        </template>
      </el-table-column>
      <el-table-column label="投放单位" align="center" prop="merchantName" />
      <el-table-column label="内容" width="100" align="center" prop="content">
        <template #default="scope">
          <el-image style="width: 50px; height: 50px;" :src="scope.row.content" :preview-src-list="[scope.row.content]"
            preview-teleported>
          </el-image>
        </template>
      </el-table-column>
      <el-table-column label="投放形式" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button link type="primary" icon="edit" @click="handleUpdate(scope.row)">投放形式</el-button>
        </template>
      </el-table-column>
      <el-table-column label="所属行业" align="center" prop="industryName" />
      <el-table-column label="所属系统" align="center" prop="systemName" />
      <el-table-column label="单位地址" align="center" prop="addressDetail" />
      <el-table-column label="法人姓名" align="center" prop="legalPersonName" />
      <el-table-column label="法人电话" align="center" prop="legalPersonPhone" />
      <el-table-column label="单位电话" align="center" prop="officeSpacePhone" />
      <el-table-column label="创建时间" align="center" prop="createTime" />
      <el-table-column label="状态" align="center" prop="isPublish">
        <template #default="scope">
          <span v-if="scope.row.isPublish == true">已发布</span>
          <span v-if="scope.row.isPublish == false">未发布</span>
        </template>
      </el-table-column>
      <el-table-column label="操作人员" align="center" prop="updateUserName" />

    </el-table>

    <pagination v-show="total > 0" :total="total" v-model:page="queryParams.currentPage"
      v-model:limit="queryParams.pageSize" @pagination="getList" />
    <!-- 添加或修改审核对话框 -->
    <el-dialog title="滚动图片投放详情" v-model="open" width="780px" append-to-body>
      <el-form ref="noticeRef" :model="form" :rules="rules" label-width="80px">
        <el-row>

          <el-col :span="12">
            <el-form-item label="投放范围" prop="scope">
              <el-select v-model="form.scope" placeholder="">
                <el-option v-for="item in scopeList" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="投放时间" prop="timeList">
              <el-input v-model="form.timeList" placeholder="请输入时间" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="投放位置" prop="position">
              <el-select v-model="form.position" placeholder="">
                <el-option v-for="item in arr2" :key="item.value" :label="item.title" :value="item.type">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="投放日期" prop="dateList">
              <el-input v-model="form.dateList" placeholder="请输入日期" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="投放次数" prop="times">
              <el-input v-model="form.times" placeholder="请输入次数" />
            </el-form-item>
          </el-col>

          
        </el-row>
      </el-form>
    </el-dialog>
  </div>
</template>

<script setup name="Notice">



let arr = []
const arr1 = [
  { title: "用户端云平台界面头条位", type: 1, checked: false },
  { title: "用户端云平台界面次条位", type: 2, checked: false },
  { title: "用户端医疗机构界面头条位", type: 3, checked: false },
  { title: "用户端医疗机构界面次条位", type: 4, checked: false },
  { title: "用户端护工抢单界面头条位", type: 5, checked: false },
  { title: "用户端护工抢单界面次条位", type: 6, checked: false },
  { title: "用户端状态查询界面头条位", type: 7, checked: false },
  { title: "用户端状态查询界面次条位", type: 8, checked: false },
  /*  */
  { title: "管理端医疗机构界面头条位", type: 9, checked: false },
  { title: "管理端医疗机构界面次条位", type: 10, checked: false },
  { title: "管理端日常经营界面头条位", type: 11, checked: false },
  { title: "管理端日常经营界面次条位", type: 12, checked: false },
  { title: "管理端生产物流界面头条位", type: 13, checked: false },
  { title: "管理端生产物流界面次条位", type: 14, checked: false },
];
const arr2 = [
  { title: "用户端云平台界面图片位", type: 1, checked: false },
  { title: "用户端医疗机构界面图片位", type: 2, checked: false },
  { title: "用户端护工抢单界面图片位", type: 3, checked: false },
  { title: "用户端状态查询界面图片位", type: 4, checked: false },
  /*  */
  { title: "管理端医疗机构界面图片位", type: 5, checked: false },
  { title: "管理端日常经营界面图片位", type: 6, checked: false },
  { title: "管理端生产物流界面图片位", type: 7, checked: false },
];

let scopeList = [
  { label: "所在地一公里内发布", value: 1 },
  { label: "所在区县内发布", value: 2 },
  { label: "所在市内发布", value: 3 },
  { label: "所在省内发布", value: 4 },
  { label: "所在全国内发布", value: 5 },
]

import {
  authApiIndustryList
} from "@/api/login.js";
const industryList = ref([])
function authApiIndustryListApi() {
  authApiIndustryList().then(
    (res) => {
      industryList.value = [...res];
    }
  );
}
onMounted(() => {
  authApiIndustryListApi()
})

import { ElMessageBox } from 'element-plus'

import {
  advertisementApisupervisedetail,
  advertisementApipicturesuperviselist,
  advertisementApiApplyHandle
} from "@/api/backAdvertisement/backAdvertisement";
import {
  getNotice,
  addNotice,
  updateNotice,
} from "@/api/system/notice";



const { proxy } = getCurrentInstance();
const { sys_notice_status, sys_notice_type } = proxy.useDict(
  "sys_notice_status",
  "sys_notice_type"
);

const noticeList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");

const data = reactive({
  form: {},
  queryParams: {
    currentPage: 1,
    pageSize: 10,
    noticeTitle: undefined,
    createBy: undefined,
    status: undefined,
  },
  rules: {
  },
});

const { queryParams, form, rules } = toRefs(data);

/** 查询审核列表 */
function getList() {
  loading.value = true;
  advertisementApipicturesuperviselist(queryParams.value).then((response) => {
    noticeList.value = response.records;
    total.value = response.total;
    loading.value = false;
  });
}

/** 取消按钮 */
function cancel() {
  open.value = false;
  reset();
}

/** 表单重置 */
function reset() {
  form.value = {
    "position": 0,
    "scope": 0,
    "times": 0,
    "dateList": [
    ],
    "timeList": [
    ]
  };
  proxy.resetForm("noticeRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.currentPage = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

/** 多选框选中数据 */
function handleSelectionChange(selection) {
  ids.value = selection.map((item) => item.advertisementId);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}


/** 新增按钮操作 */
function handleAdd() {
  reset();
  open.value = true;
  title.value = "添加审核";
}

/**修改按钮操作 */
function handleUpdate(row) {
  reset();
  const advertisementId = row.advertisementId || ids.value;
  advertisementApisupervisedetail(advertisementId).then((response) => {
    form.value = response;
    open.value = true;
    title.value = "投放形式";
  });
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["noticeRef"].validate((valid) => {
    if (valid) {
      if (form.value.advertisementId != undefined) {
        updateNotice(form.value).then((response) => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        });
      } else {
        addNotice(form.value).then((response) => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      }
    }
  });
}

/** 删除按钮操作 */
function handleDelete(row) {
  const advertisementIds = row.advertisementId || ids.value;
  const advertisementContent = row.content || ids.value;
  ElMessageBox.confirm('是否确认审核内容为"' + advertisementContent + '"的数据项？', "系统提示", {
    confirmButtonText: '同意',
    cancelButtonText: '拒绝',
    type: "warning",
    distinguishCancelAndClose: true,
  }).then(function (e) {
    console.log(e, "then");
    advertisementApiApplyHandle({
      advertisementId: advertisementIds,
      handle: true
    });
  }).catch((action) => {
    console.log(action, 'action');
    if (action == 'cancel') {
      advertisementApiApplyHandle({
        advertisementId: advertisementIds,
        handle: false
      });
    }
  });
  getList();
}

getList();
</script>